#!/usr/bin/env python
# coding: utf-8

# # 通用场景识别
# * 1.通用文字识别
# * 2.网络图片文字识别
# * 3.二维码识别

# In[1]:


# encoding:utf-8
import requests 

# client_id 为官网获取的AK， client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?'

# 准备URL参数
payload = {
    'grant_type':'client_credentials',
    'client_id':'',
    'client_secret':'tpG69acq8hmY9D5hRlCaKka7QeoUVU2c'
}
response = requests.get(host)
if response:
    print(response.json())


# In[2]:


response.json()


# In[8]:


# encoding:utf-8
import requests 

# client_id 为官网获取的AK， client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=xApuSIuqSW8Fwv85yTicatIu&client_secret=Kn18k6dVntHcFUSaGuSpe0DqKocRuB8d'
response = requests.get(host)
if response:
    print(response.json())


# In[9]:


# encoding:utf-8

import requests
import base64

'''
通用文字识别（高精度版）
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
# 二进制方式打开图片文件
f = open('wenzi.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '24.fd4313fb9ef0ee61170d1e6de3f62686.2592000.1652272740.282335-25946432'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[ ]:





# In[ ]:





# In[10]:


# encoding:utf-8

import requests
import base64

'''
网络图片文字识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage"
# 二进制方式打开图片文件
f = open('wangluo.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '24.fd4313fb9ef0ee61170d1e6de3f62686.2592000.1652272740.282335-25946432'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[ ]:





# In[ ]:





# In[11]:


# encoding:utf-8

import requests
import base64

'''
二维码识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/qrcode"
# 二进制方式打开图片文件
f = open('erweima.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '24.fd4313fb9ef0ee61170d1e6de3f62686.2592000.1652272740.282335-25946432'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[ ]:





# In[ ]:





# # 卡证文字识别
# * 1.身份证或者银行卡

# In[12]:


# encoding:utf-8

import requests
import base64

'''
身份证识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard"
# 二进制方式打开图片文件
f = open('shengfz.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"id_card_side":"front","image":img}
access_token = '24.fd4313fb9ef0ee61170d1e6de3f62686.2592000.1652272740.282335-25946432'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[ ]:





# In[ ]:





# # 增税发票识别

# In[13]:


# encoding:utf-8

import requests
import base64

'''
增值税发票识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/vat_invoice"
# 二进制方式打开图片文件
f = open('fapiao.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '24.fd4313fb9ef0ee61170d1e6de3f62686.2592000.1652272740.282335-25946432'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[ ]:




